﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices;
using Shop.Model.Dto.Mine;
using Shop.Model.View.Mine;

namespace Shop.WebApi.Controllers;

/// <summary>
/// 我的详细服务
/// </summary>
[ApiController]
[Route("Api/[controller]")]
public class MineDetailController: ShopControllerBase
{
    private readonly IMineDetailService _mineDetailService;
    private readonly IUserContext _userContext;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="mineDetailService"></param>
    /// <param name="userContext"></param>
    public MineDetailController(IMineDetailService mineDetailService,IUserContext userContext)
    {
        _mineDetailService = mineDetailService;
        _userContext = userContext;
    }
    
    /// <summary>
    /// 我的钱包日志
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("WalletList")]
    public AppResult<PageModel<MyWalletListVo>> MyWalletList([FromQuery]MyWalletListDto dto)
        => _mineDetailService.MyWalletList(_userContext.Id, dto);

    /// <summary>
    /// 我的钱包日志类型
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("WalletType")]
    public AppResult<List<MyWalletTypeVo>> MyWalletType()
    {
        var myWalletTypeVo = new List<MyWalletTypeVo>();
        var myWalletTypeInfoOne = new MyWalletTypeVo(){Type = 0, Name = "全部类型", Sort = 0};
        var myWalletTypeInfoTwo = new MyWalletTypeVo(){Type = 1, Name = "收入", Sort = 1};
        var myWalletTypeInfoThree = new MyWalletTypeVo(){Type = 2, Name = "收入(待结算)", Sort = 2};
        var myWalletTypeInfoFour = new MyWalletTypeVo(){Type = 3, Name = "订单支付", Sort = 3};
        var myWalletTypeInfoFive = new MyWalletTypeVo(){Type = 4, Name = "余额提现", Sort = 4};
        var myWalletTypeInfoSix = new MyWalletTypeVo(){Type = 5, Name = "余额提现(申请中)", Sort = 5};
        var myWalletTypeInfoSeven = new MyWalletTypeVo(){Type = 6, Name = "订单退款", Sort = 6};
        myWalletTypeVo.Add(myWalletTypeInfoOne);
        myWalletTypeVo.Add(myWalletTypeInfoTwo);
        myWalletTypeVo.Add(myWalletTypeInfoThree);
        myWalletTypeVo.Add(myWalletTypeInfoFour);
        myWalletTypeVo.Add(myWalletTypeInfoFive);
        myWalletTypeVo.Add(myWalletTypeInfoSix);
        myWalletTypeVo.Add(myWalletTypeInfoSeven);
        return myWalletTypeVo;
    }
    
    /// <summary>
    /// 我的钱包日志类型
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("EarningsType")]
    public AppResult<List<MyWalletTypeVo>> MyEarningsType()
    {
        var myWalletTypeVo = new List<MyWalletTypeVo>();
        var myWalletTypeInfoOne = new MyWalletTypeVo(){Type = 0, Name = "全部类型", Sort = 0};
        var myWalletTypeInfoTwo = new MyWalletTypeVo(){Type = 1, Name = "销售佣金", Sort = 1};
        var myWalletTypeInfoThree = new MyWalletTypeVo(){Type = 2, Name = "销售分红", Sort = 2};
        var myWalletTypeInfoFour = new MyWalletTypeVo(){Type = 3, Name = "定期分红", Sort = 3};
        myWalletTypeVo.Add(myWalletTypeInfoOne);
        myWalletTypeVo.Add(myWalletTypeInfoTwo);
        myWalletTypeVo.Add(myWalletTypeInfoThree);
        myWalletTypeVo.Add(myWalletTypeInfoFour);
        return myWalletTypeVo;
    }

    /// <summary>
    /// 我的收益明细数值
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("EarningsStatistics")]
    public AppResult<MyEarningsStatisticsVo> MyEarningsStatistics([FromQuery]MyEarningsListDto dto)
    {
        if (dto.TimeType == 2 && dto.Time.HasValue)
        {
            dto.Time = new DateTime(dto.Time.Value.Year, dto.Time.Value.Month, 1);
        }
        return _mineDetailService.MyEarningsStatistics(_userContext.Id, dto);
    }
    
    /// <summary>
    /// 我的收益明细列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("EarningsList")]
    public AppResult<PageModel<MyEarningsListVo>> MyEarningsList([FromQuery]MyEarningsListDto dto)
        => _mineDetailService.MyEarningsList(_userContext.Id, dto);
    
    /// <summary>
    /// 我的顾客会员数据
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("CustomerData")]
    public AppResult<MyCustomerDataVo> MyCustomerData()
        => _mineDetailService.MyCustomerData(_userContext.Id);

    /// <summary>
    /// 我的顾客会员等级
    /// 普通用户（普通用户）、VIP（VIP1）、SVIP（VIP2）、行家（VIP3）、服务中心（VIP4）、服务中心（VIP5）
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("CustomerGrade")]
    public AppResult<List<UserGradeVo>> MyCustomerGrade()
    {
        var userGradeList = new List<UserGradeVo>();
        var myWalletTypeInfoOne = new UserGradeVo(){Grade = 0, Name = "全部用户", Sort = 0};
        var myWalletTypeInfoTwo = new UserGradeVo(){Grade = 1, Name = "普通", Sort = 1};
        var myWalletTypeInfoThree = new UserGradeVo(){Grade = 2, Name = "会员", Sort = 2};
        var myWalletTypeInfoFour = new UserGradeVo(){Grade = 3, Name = "至尊", Sort = 3};
        var myWalletTypeInfoFive = new UserGradeVo(){Grade = 4, Name = "行家", Sort = 4};
        userGradeList.Add(myWalletTypeInfoOne);
        userGradeList.Add(myWalletTypeInfoTwo);
        userGradeList.Add(myWalletTypeInfoThree);
        userGradeList.Add(myWalletTypeInfoFour);
        userGradeList.Add(myWalletTypeInfoFive);
        return userGradeList;
    }

    /// <summary>
    /// 我的顾客会员列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Route("CustomerList")]
    public AppResult<PageModel<MyCustomerListVo>> MyCustomerList([FromQuery] MyCustomerListDto dto)
        => _mineDetailService.MyCustomerList(_userContext.Id, dto);

    /// <summary>
    /// 提现信息
    /// </summary>
    /// <returns></returns>
    [HttpGet("UserBalance")]
    public AppResult<UserBalanceVo> UserBalance()
        => _mineDetailService.UserBalance(_userContext.Id);

    /// <summary>
    /// 用户提现
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("Drawings")]
    public AppResult Drawings(DrawingsDto dto)
        => _mineDetailService.Drawings(dto, _userContext.Id);
}